/*global QUnit: false, CrocMSRP: false*/

QUnit.module("parser");

(function () {
	var lineEnd = '\r\n';

	QUnit.test("Big chunk", function(assert) {
		var msg = '';
		msg += 'MSRP nwkyvqj5 SEND' + lineEnd;
		msg += 'To-Path: msrp://d2j2j7zd.invalid:2855/7m83o67g7f;ws' + lineEnd;
		msg += 'From-Path: msrps://192.168.0.74:2855/s.4651.23.1243343917;tcp msrps://192.168.0.74:2855/s.4652.25.1170933372;tcp msrp://kc4cflb1.invalid:2855/h484gubk2r;ws' + lineEnd;
		msg += 'Message-ID: 3560782744.nioym224' + lineEnd;
		msg += 'Success-Report: yes' + lineEnd;
		msg += 'Failure-Report: yes' + lineEnd;
		msg += 'Byte-Range: 1-2048/10240' + lineEnd;
		msg += 'Content-Disposition: inline' + lineEnd;
		msg += 'Content-Type: text/plain' + lineEnd;
		msg += lineEnd;
		msg += '12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678' + lineEnd;
		msg += '-------nwkyvqj5+' + lineEnd;
		
		msg = CrocMSRP.parseMessage(msg);
		assert.ok(msg instanceof CrocMSRP.Message.Message, 'It\'s a Message');
		assert.ok(msg instanceof CrocMSRP.Message.Request, 'It\'s a Request');
		assert.ok(msg instanceof CrocMSRP.Message.IncomingRequest, 'It\'s an IncomingRequest');
		assert.strictEqual(msg.method, 'SEND', 'Method');
		assert.strictEqual(msg.tid, 'nwkyvqj5', 'Transaction ID');
		assert.deepEqual(msg.toPath, ['msrp://d2j2j7zd.invalid:2855/7m83o67g7f;ws'], 'To Path');
		assert.deepEqual(msg.fromPath, [
				'msrps://192.168.0.74:2855/s.4651.23.1243343917;tcp',
				'msrps://192.168.0.74:2855/s.4652.25.1170933372;tcp',
				'msrp://kc4cflb1.invalid:2855/h484gubk2r;ws'
			], 'From Path');
		assert.strictEqual(msg.messageId, '3560782744.nioym224', 'Message ID');
		assert.deepEqual(msg.responseOn, {success: true, failure: true}, 'Message ID');
		assert.strictEqual(msg.messageId, '3560782744.nioym224', 'Message ID');
		assert.strictEqual(msg.byteRange.start, 1, 'Range start');
		assert.strictEqual(msg.byteRange.end, 2048, 'Range end');
		assert.strictEqual(msg.byteRange.total, 10240, 'Range total');
		assert.deepEqual(msg.contentDisposition, {type: 'inline', param: {}}, 'Content Disposition');
		assert.strictEqual(msg.contentType, 'text/plain', 'Content Type');
		assert.strictEqual(msg.body.length, 2048, 'Body');
		assert.strictEqual(msg.body.charAt(0), '1', 'Body start');
		assert.strictEqual(msg.body.charAt(2047), '8', 'Body end');
		assert.strictEqual(msg.continuationFlag, CrocMSRP.Message.Flag.continued, 'Body end');
	});
	
}());
